package cn.zysheep.proxy.jdk_proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @ClassName: ProxyFactory
 * @Description: TODO(一句话描述该类的功能)
 * @Author: lyw
 * @Date: 2022/10/26 21:48
 */
public class ProxyFactory {

    private TrainStation sellTickets = new TrainStation();

    private SellTickets getProxyObject() {
        SellTickets instance = (SellTickets)Proxy.newProxyInstance(sellTickets.getClass().getClassLoader(),
                sellTickets.getClass().getInterfaces(),
                new InvocationHandler() {
                    @Override
                    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                        System.out.println("代理点收取一些服务费用(JDK动态代理方式)");
                        Object invoke = method.invoke(sellTickets, args);
                        return invoke;
                    }
                });
        return instance;
    }
}
